package cn.platform.controller;

import cn.platform.entity.Student;
import cn.platform.response.ResultStudent;
import cn.platform.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

@RestController
@RequestMapping("/api/students")
public class StudentController1 {

    @Autowired
    private StudentService studentService;

    @GetMapping
    public ResultStudent<List<Student>> listAll() {
        List<Student> students = studentService.listAllActiveStudents();
        return ResultStudent.success(students);
    }

    @GetMapping("/search")
    public ResultStudent<List<Student>> searchByName(@RequestParam String name) {
        List<Student> students = studentService.searchByName(name);
        return ResultStudent.success(students);
    }
}